package com.game.spacetrader.TradeGoods;

import java.util.*;

import com.game.spacetrader.Planet;
import com.game.spacetrader.data.Data;

/**
 * Gets TradeGood data from the fusion table
 */
public class TradeGoodsAdaptor {
	public static ArrayList<TradeGoods> goods,cargo;

	/**
	 * Returns the goods for the planet passed in
	 * 
	 * @param p
	 * @return
	 */
	public static ArrayList<TradeGoods> getAllGoods(Planet p){
		Data trade = new Data("market.db");
		goods = new ArrayList<TradeGoods>();
		//TODO MAKE SO CAN GET CALL # ROWS IN DATABASE  (AASHISH)

		//NOT SURE IF * CHARACTER WORKS... 
		String data;
		Scanner scan;
		TradeGoods tg;
		String[] col = new String[12];
		for(int i = 0; i < 10; i++){
			data = trade.execSQL("SELECT * FROM @TABLE WHERE ID=" + i)[0]; 
			scan = new Scanner(data);
			for(int j = 0; j < 12; j++)
				col[j] = scan.next();
			//public TradeGoods(String name,int basePrice,int mtlp,int mtlu, int ttp, int ipl, int var,Planet p){
			tg = new TradeGoods(col[0], Integer.parseInt(col[4]), Integer.parseInt(col[1]), Integer.parseInt(col[2]),
					Integer.parseInt(col[3]), Integer.parseInt(col[5]), Integer.parseInt(col[6]),p);
			goods.add(tg);
		}
		goods.add(new TradeGoods("gas",10,0,0,0,0,100,p));
		return goods;
	}
	/**
	 * @return cargo in the hull
	 */
	public static ArrayList<TradeGoods> getCargo(){
		Data trade = new Data("market.db");
		cargo = new ArrayList<TradeGoods>();
		//TODO MAKE SO CAN GET CALL # ROWS IN DATABASE  (AASHISH)
			//NOT SURE IF * CHARACTER WORKS... 
		String data;
		Scanner scan;
		TradeGoods tg;
		String[] col = new String[12];
		for(int i = 0; i < 10; i++){
			data = trade.execSQL("SELECT * FROM @TABLE WHERE ID=" + i)[0]; 
			scan = new Scanner(data);
			for(int j = 0; j < 12; j++)
				col[j] = scan.next();
			//TODO THESE VALS NEED TO BE CHANGED TO MATCH THE COLUMN NAMES WITH THE CONSTRUCTOR VARS (STEVEN)
			tg = new TradeGoods(col[0], Integer.parseInt(col[4]), Integer.parseInt(col[1]), Integer.parseInt(col[2]),
				Integer.parseInt(col[3]), Integer.parseInt(col[5]), Integer.parseInt(col[6]),0);
			cargo.add(tg);
		}

		return cargo;
	}
}
